﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PPIDE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.richTextBox2.Text = string.Empty;
            string[] text = this.richTextBox1.Text.Split('\n');
            if (text.Length > 0)
            {
                for (int i = 0; i < text.Length; i++)
                {
                    try
                    {
                        this.richTextBox2.Text += "line[" + (i+1) + "]:" + PpCompiler.TranslateAsmLine(ref text[i], i+1).ToString("X")+"\n";
                    }
                    catch (Exception ex)
                    {
                        this.richTextBox2.Text += "line[" + (i +1)+ "]:" + ex.Message+"\n";
                       
                    }
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Int16 x = -1;
            int y = x;
            this.richTextBox2.Text = string.Empty;
            string[] text = this.richTextBox1.Text.Split('\n');
            try
            {
                byte[] mcodes = PpCompiler.TranslateAsmLines(ref text);
                for (int i = 0; i < mcodes.Length / 4; i++)
                {
                    this.richTextBox2.Text +=(i*4).ToString("X8")+": " +string.Format("{0:X2} {1:X2} {2:X2} {3:X2}\n", mcodes[i * 4], mcodes[i * 4 + 1], mcodes[i * 4 + 2], mcodes[i * 4 + 3]);
                }
                //PpCompiler.WriteBinFile(ref mcodes, "c:/test.bin");
                PpCompiler.WriteHdlSimMemBankFile(ref  mcodes, "c:/banksim/");
                this.richTextBox2.Text += PpSim.Execute(ref mcodes);
            }
            catch (Exception ex)
            {
                this.richTextBox2.Text +=ex.Message + "\n";

            }
        }
    }
}
